<?php

/**
 * 帮助中心接口
 * 
 * @author zhangbo <zhyangbo@shopexunit.com>
 */
class mobileapi_rpc_helps {

    /**
     * 构造函数
     * 
     * @param app $app
     */
    function __construct($app) {
        $this->app = $app;
    }

    /**
     * 帮助中心文档列表
     * 
     * @param array $params 录入参数
     * 
     * @return array 文档列表
     */
    function get_all_list1($params) {
        $last_id = intval($params['last_id']) ? intval($params['last_id']) : 0;
        $page = intval($params['page']) ? intval($params['page']) : 1;
        $limit = intval($params['limit']) ? intval($params['limit']) : 20;

        $sql_count = "select count(*) as _count from " . kernel::database()->prefix . "content_article_helps "
                . "order by article_id DESC ";
        $rows = kernel::database()->select($sql_count);

        $totalPage = intval($rows[0]['_count']);
        $sql = "select * from " . kernel::database()->prefix . "content_article_helps "
                . "order by article_id DESC ";
        $lists = kernel::database()->selectLimit($sql, $limit, 0);

        return array(
            'current' => $page,
            'total' => ceil($totalPage / $limit),
            'items' => $lists,
        );
    }
    /**
     * 帮助中心文档列表
     * 
     * @param array $params 录入参数
     * 
     * @return array 文档列表
     */
    function get_all_list($params) {
        $last_id = intval($params['last_id']) ? intval($params['last_id']) : 0;
        if($last_id!==0){
            $filter = array('article_id|lthan' => $last_id);
        }else{
            $filter = array();
        }
        $limit = intval($params['limit']) ? intval($params['limit']) : 5;
        $obj=app::get('content')->model('article_helps');
        $totalPage = $obj->count();
        $lists = $obj->getList('*',$filter,0,$limit,'article_id DESC');
	//2018-3-7 将数据集中的image_id改成图片的url地址
        foreach($lists as &$v) {
            $v['image_id'] = base_storager::image_path($v['image_id']);
        }
        if(is_array($lists)){
            $new_items = end($lists);
            $new_last_id = $new_items['article_id'];
        }
        return array(
            'total'   => ceil($totalPage / $limit),
            'items'   => isset($params['last_id'])?$lists:NULL,
            'last_id' =>$new_last_id,
        );
    }

    /**
     * 帮助中心文档详情
     * 
     * @param array $params 录入参数
     * 
     * @return array 文档详情
     */
    function get_detail() {
        $article_id = $_REQUEST['article_id'];
        $detail = kernel::single('content_helps_detail')->get_detail($article_id, false);

        return $detail;
    }

}
